#ifndef _EDBSR_H_
#define _EDBSR_H_

#include "edbd_ecx.h"

#define EDBSR_FOREACH_CHILD(conn, sr, child)		\
	for (child = edbsr_get_first(conn, sr, ECM_FALSE); child; child = edbsr_get_next_free(conn, child))

#define EDBSR_FOREACH_CHILD_RETURN(sr, res)	\
	do { tree_unlock(sr, PIN_LOCK); return (res); } while (0)

ECMBOOL edbsr_get_bool(edbd_conn_t edbd_conn, const sr_t *sr);
ecm_double edbsr_get_dbl(edbd_conn_t edbd_conn, const sr_t *sr);
ecm_int32 edbsr_get_int(edbd_conn_t edbd_conn, const sr_t *sr);
ecm_int64 edbsr_get_ll(edbd_conn_t edbd_conn, const sr_t *sr);
ecm_ptr_t edbsr_get_oct_data(edbd_conn_t edbd_conn, const sr_t *sr);
ecm_size_t edbsr_get_oct_size(edbd_conn_t edbd_conn, const sr_t *sr);
ecm_ptr_t edbsr_get_ptr(edbd_conn_t edbd_conn, const sr_t *sr);
const sr_t *edbsr_get_ref(edbd_conn_t edbd_conn, const sr_t *sr);
const char *edbsr_get_str(edbd_conn_t edbd_conn, const sr_t *sr);
sr_val_t edbsr_get_val(edbd_conn_t edbd_conn, const sr_t *sr);

sr_t *edbsr_get(edbd_conn_t edbd_conn, ecxroot_t *ecxroot, const sr_t *sr_anchor, const sr_t *sr_LNP, srt_t srt_result, ECMBOOL autopin);
sr_t *edbsr_getn(edbd_conn_t edbd_conn, const sr_t *sr_anchor, const char *LNP, ECMBOOL autopin);
sr_t *edbsr_get_child(edbd_conn_t edbd_conn, ecxroot_t *ecxroot, const sr_t *sr_group, const char *name, ECMBOOL autopin);
sr_t *edbsr_get_parent(edbd_conn_t edbd_conn, const sr_t *sr, ECMBOOL autopin);
sr_t *edbsr_get_first(edbd_conn_t edbd_conn, const sr_t *sr_group, ECMBOOL autopin);
sr_t *edbsr_get_next(edbd_conn_t edbd_conn, const sr_t *sr, ECMBOOL autopin);
sr_t *edbsr_get_next_free(edbd_conn_t edbd_conn, const sr_t *sr);
sr_t *edbsr_get_last(edbd_conn_t edbd_conn, const sr_t *sr_group, ECMBOOL autopin);
sr_t *edbsr_get_prev(edbd_conn_t edbd_conn, const sr_t *sr, ECMBOOL autopin);
char *edbsr_get_LNP(edbd_conn_t edbd_conn, const sr_t *sr);
sr_t *edbsr_get_deref(edbd_conn_t edbd_conn, const sr_t *sr);
ECMBOOL edbsr_is_ontree(edbd_conn_t edbd_conn, const sr_t *sr);

sr_t *edbsr_dup(edbd_conn_t edbd_conn, const sr_t *sr_src);

sr_t *edbsr_xecreate(edbd_conn_t edbd_conn, sr_t *sr_HMS, const char *name, srt_t srt);
sr_t *edbsr_xeappend(edbd_conn_t edbd_conn, sr_t *sr_HMS, sr_t *sr_xe_SA);
ECMBOOL edbsr_xedelete(edbd_conn_t edbd_conn, sr_t *sr_xe, ECMBOOL force);

edb_err_t edbsr_assign(edbd_conn_t edbd_conn, sr_t *sr_assigned, sr_t *sr_operand);
edb_err_t edbsr_set_val(edbd_conn_t edbd_conn, sr_t *sr_assigned, sr_val_t val);
edb_err_t edbsr_set_ref(edbd_conn_t edbd_conn, sr_t *sr, sr_t *sr_LNP);
edb_err_t edbsr_set_target(edbd_conn_t edbd_conn, sr_t *sr, const sr_t *sr_target);
sr_val_t edbsr_cpy_val(edbd_conn_t edbd_conn, sr_t *sr);
edb_err_t edbsr_clear_val(edbd_conn_t edbd_conn, sr_t *sr);

int edbsr_get_num_child(edbd_conn_t edbd_conn, const sr_t *sr_group);

void edbsr_insert_pin(edbd_conn_t edbd_conn, sr_t *sr);
void edbsr_release(sr_t *sr, ECMBOOL autopin, ECMBOOL from_get);

#endif
